import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import register from '@/components/register'
import login from '@/components/login'
import myprofile from '@/components/myprofile'
import mypic from '@/components/mypic'
import addgoods from '@/components/addgoods'
import search from '@/components/search'




// 考试组件
import profile from '@/components/ex_profile'
import reg from '@/components/reg'
import log from '@/components/log'
import upyun from '@/components/upyun'
import goodslist from '@/components/goodslist'
import mysearch from '@/components/mysearch'

Vue.use(Router)

var routes = [

        //考试路由
        {
          path:'/mysearch',
          name:'mysearch',
          component:mysearch
        },
        {
          path:'/goodslist',
          name:'goodslist',
          component:goodslist
        },
        {
          path:'/upyun',
          name:'upyun',
          component:upyun
        },
        {
          path:'/profile',
          name:'profile',
          component:profile
        },
        {
          path:'/log',
          name:'log',
          component:log
        },
        {
          path:'/reg',
          name:'reg',
          component:reg
        },





        //项目路由
        {
          path:'/search',
          name:'search',
          component:search
        },
        {
          path:'/addgoods',
          name:'addgoods',
          component:addgoods
        },

        {
          path:'/mypic',
          name:'mypic',
          component:mypic
        },

        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          beforeEnter: (to, from, next) => {
            
            if (localStorage.getItem('username')){

              console.log('已经登陆');
              next();
            }else{
              console.log('没有登陆');
              next('/login');
            }
          }
        },
        {
          path:'/login',
          name:'login',
          component:login
        },

        {
          path:'/register',
          name:'register',
          component:register
        },

        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        }
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
